package cn.wolfcode.wolf2w.business.listen;

import cn.wolfcode.wolf2w.api.domain.Question;
import cn.wolfcode.wolf2w.api.domain.QuestionSearch;
import cn.wolfcode.wolf2w.business.repository.QuestionRepository;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浪兎兎
 * @since 2025-06-16 13:38
 */
@Component
public class QuestionListener {
    @Autowired
    private QuestionRepository questionRepository;
    @RabbitListener(queues = {"questionQueue"})
    public void onMessage(String message) {
        Question question = JSON.parseObject(message, Question.class);
        QuestionSearch questionSearch = new QuestionSearch();
        BeanUtils.copyProperties(question, questionSearch);
        questionRepository.save(questionSearch);
    }
}
